package demo01extends;

import java.util.ArrayList;
import java.util.Random;

/*
 * 使用集合存储20个随机数字，
 * 筛选偶数，存储到小集合中
 * 自定义方法进行筛选
 *
 *
 * */
public class Demo07ArrayListReturn {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> listResult;
        Random r = new Random();
        for (int i = 0; i < 20; i++) {
            int num = r.nextInt(100)+1;
            list.add(num);
        }
        listResult = ArrayListReturn(list);
        System.out.println(listResult.size()+":"+listResult);

    }

    public static ArrayList<Integer> ArrayListReturn(ArrayList<Integer> list) {
        ArrayList<Integer> listResult = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int num = list.get(i);
            if (num % 2 == 0) {
                listResult.add(num);
            }
        }
        return listResult;
    }

}
